package com.jltx.xq.simplewatch.news.api;

import com.jltx.xq.simplewatch.commons.ApiConstants;
import com.jltx.xq.simplewatch.utils.GsonFactoryUtils;
import com.jltx.xq.simplewatch.utils.OkhttpClientFactoryUtils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/08/22.
 */

public class WeChatApiService {
    private Retrofit retrofit;
    private WeChatApi weChatApi;
    private WeChatApiService() {

        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.WECHAT_BASE_URL)
                .client(OkhttpClientFactoryUtils.getInstance().getOkHttpClient())
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonFactoryUtils.providerGsonConverterFactory())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        weChatApi = retrofit.create(WeChatApi.class);

    }

    public WeChatApi getWeChatApi() {
        return weChatApi;
    }

    public static WeChatApiService getInstance(){
        return WeChatApiServiceHolder.sInstance;
    }

   private static class WeChatApiServiceHolder{
        private static final WeChatApiService sInstance = new WeChatApiService();
    }

}
